// indattach/getprize/getprize.js
const app = getApp();
Page({
  data: {

  },
  onLoad: function(options) {
    var that=this
    app.comrequest('https://ipass.cc/myapi/getprizeapi.php',{num:0}).then(res=>{
      // console.log(res)
      that.setData({
        prizeimg:res.getprizeimg,
        prizetext:res.getprizexz,
        prizekt:res.prizekt
      })
    })
  },
  wxlogin(e) {
    var that=this
    var prizekt=that.data.prizekt 
    if(prizekt==0){
      wx.showToast({
        title: '未开通',
        icon:'none'
      })
    }else if(prizekt==1){
      wx.requestSubscribeMessage({
        tmplIds: ["Or5eFsHJmlRo1MJcV8fMaOnmXG_gHMD6njrvdUEOPzY"],
        success (res) {
          // console.log(res)
            if(res.Or5eFsHJmlRo1MJcV8fMaOnmXG_gHMD6njrvdUEOPzY === "accept"){
              app.comrequest('https://ipass.cc/myapi/getprizeapi.php',{num:1,openid:app.globalData.openid}).then(res=>{
                if(res=="领取成功"){
                  wx.navigateTo({
                    url: '../getpcg/getpcg',
                  })
                }else if(res=="你已领取过"){
                  wx.showToast({
                    title: res,
                    icon:'none'
                  })
                }
              })
            }
          }
      })
    } 
}

})